package com.act.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.act.domain.Depart;
import com.act.dto.PagerDTO;
import com.act.dto.Response;
import com.act.service.api.IDepartService;
import com.act.util.LoggerUtil;
import com.act.vo.PagerVo;

@Controller
@RequestMapping("/depart")
public class DepartController {

	@Resource
	private IDepartService departService;
	
	private final Logger LOGGER = Logger.getLogger(DepartController.class);	

	@RequestMapping(value="/get",method=RequestMethod.POST)
	@ResponseBody
	public Response getAll(@RequestBody PagerDTO pagerDTO){
		try {
			PagerVo<Map> amlist=departService.getAll(pagerDTO);

			return Response.success(amlist);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
	}
	
	@RequestMapping(value="/getAll",method=RequestMethod.GET)
	@ResponseBody
	public Response getAllList(){
		try {
			List<Depart> amlist=departService.getAllList();

			return Response.success(amlist);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
	}
	
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Response update(Depart depart) {
    	 try {
    		 departService.update(depart);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
	
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(Depart depart) {
    	 try {
    		 departService.add(depart);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
    }    
    
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Response delete(@PathVariable int id) {
    	 try {
    		 departService.delete(id);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
    }      
    
    @RequestMapping(value = "/getById/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Response getById(@PathVariable int id) {
    	 try {
    		 Depart depart = departService.getById(id);
             return Response.success(depart);
         } catch (Exception e) {
           
             return Response.fail();
         }
    }
}
